package org.bet.service;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bet.dao.SyndicatorDao;
import org.bet.domain.Syndicator;
import org.bet.exception.BETException;
import org.bet.exception.BETExceptionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SyndicatorService {
	private final Log logger = LogFactory.getLog(getClass());
	
	@Autowired
	private BETExceptionFactory exceptionFactory;
	
	@Autowired
	private SyndicatorDao syndicatorDao;
	
	
	
	public void saveOrUpdateSyndicator(Syndicator syndicator) throws BETException{
		try{
			if(syndicator != null){			
//				if(!syndicatorDao.existsSyndicator(syndicator.getId())){
//					syndicatorDao.insertSyndicator(syndicator);
//				}
//				else{
//					syndicatorDao.updateSyndicator(syndicator);
//				}
				syndicatorDao.saveOrUpdateSyndicator(syndicator);
			}
		}
		catch(Exception e){
			logger.error(e);
			throw exceptionFactory.createException("error.syndicatorService.saveOrUpdate", new Object[]{ syndicator.getId() }, e);
		}
		
	}

	public Syndicator getSyndicator(String id) throws BETException {
		try{
			return syndicatorDao.getSyndicator(id);
		}
		catch(Exception e){
			logger.error(e);
			throw exceptionFactory.createException("error.syndicatorService.get", new Object[]{ id }, e);
		}
	}

}
